package com.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.*;
import com.example.flowable.service.FlowableModelService;
import com.example.model.title.service.TitleModelService;
import com.example.utils.StringUtils;

import java.util.Map;

/**
 * @Classname WordController
 * @Description TODO
 * @Date 2022/8/6 23:04
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@Auth
@Controller("/")
public class FreemarkerController {

    @Autowired
    private FlowableModelService flowableModelService;

    @GetMapping("index")
    public String getIndexController(
                                    @Param(value = "pageNum",defalultValue = "1")Integer pageNum,
                                    @Param(value = "pageSize",defalultValue = "20")Integer pageSize,
                                    @Param(value = "keyword",required = false)String search,
                                     @Param(value = "test",required = false)String test,
                                     Map<String,Object> map){
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        if(!StringUtils.isEmpty(search)){
            map.put("keyword",search);
        }
        return "index.html";
    }

    @GetMapping(value = "content",desc = "内容页")
    public String getContentController(@Param(value = "contentId",required = false)Integer contentId,
                                       Map<String,Object> map){
        if(contentId==null){
            return "index.html";
        }
        map.put("contentId",contentId);
        System.out.println(contentId);
        return "content.html";
    }

    @GetMapping(value = "addcontent",desc = "内容添加页")
    public String addContentController(){
        return "addcontent.html";
    }


    @GetMapping(value = "form",desc = "打开表单")
    public String getFormController(Map<String,Object> map,
                                    @Param(value = "fromId")String fromId,
                                    @Param(value = "id",required = false)Integer id){
        if(fromId == null){
            return "index.html";
        }
        map.put("id",fromId);
        map.put("dataId",id==null? "" : id);
        return "form/processForm.html";
    }

    @GetMapping(value = "tableForm")
    public String testController(){

        return "form/demo.html";
    }



    @GetMapping("tree")
    public String treeController(){
        return "tree.html";
    }
}
